package userservice

import (
	"context"
	user "cwgoexample/kitex_gen/user"

	"cwgoexample/kitex_gen/user/userservice"
	"github.com/cloudwego/kitex/client"
	"github.com/cloudwego/kitex/client/callopt"
)

type RPCClient interface {
	KitexClient() userservice.Client
	Service() string
	AddUser(ctx context.Context, user *user.User, callOptions ...callopt.Option) (r bool, err error)
	DeleteUser(ctx context.Context, id int64, callOptions ...callopt.Option) (r bool, err error)
	EditUser(ctx context.Context, user *user.User, callOptions ...callopt.Option) (r bool, err error)
	GetUserInfo(ctx context.Context, user *user.User, callOptions ...callopt.Option) (r *user.User, err error)
	GetUserList(ctx context.Context, offset int64, limit int64, callOptions ...callopt.Option) (r []*user.User, err error)
}

func NewRPCClient(dstService string, opts ...client.Option) (RPCClient, error) {
	kitexClient, err := userservice.NewClient(dstService, opts...)
	if err != nil {
		return nil, err
	}
	cli := &clientImpl{
		service:     dstService,
		kitexClient: kitexClient,
	}

	return cli, nil
}

type clientImpl struct {
	service     string
	kitexClient userservice.Client
}

func (c *clientImpl) Service() string {
	return c.service
}

func (c *clientImpl) KitexClient() userservice.Client {
	return c.kitexClient
}

func (c *clientImpl) AddUser(ctx context.Context, user *user.User, callOptions ...callopt.Option) (r bool, err error) {
	return c.kitexClient.AddUser(ctx, user, callOptions...)
}

func (c *clientImpl) DeleteUser(ctx context.Context, id int64, callOptions ...callopt.Option) (r bool, err error) {
	return c.kitexClient.DeleteUser(ctx, id, callOptions...)
}

func (c *clientImpl) EditUser(ctx context.Context, user *user.User, callOptions ...callopt.Option) (r bool, err error) {
	return c.kitexClient.EditUser(ctx, user, callOptions...)
}

func (c *clientImpl) GetUserInfo(ctx context.Context, user *user.User, callOptions ...callopt.Option) (r *user.User, err error) {
	return c.kitexClient.GetUserInfo(ctx, user, callOptions...)
}

func (c *clientImpl) GetUserList(ctx context.Context, offset int64, limit int64, callOptions ...callopt.Option) (r []*user.User, err error) {
	return c.kitexClient.GetUserList(ctx, offset, limit, callOptions...)
}
